package com.geepi.soundcloud.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.geepi.soundcloud.mapper.AudioMapper;
import com.geepi.soundcloud.mapper.OrderMapper;
import com.geepi.soundcloud.model.AudioBean;
import com.geepi.soundcloud.model.RecordBean;
import com.geepi.soundcloud.service.IOrderService;


@Service
public class IOrderServiceImpl implements IOrderService{
    @Autowired
	OrderMapper orderMapper;
    @Autowired
	AudioMapper audioMapper;
    
	public List<RecordBean> queryHistoryOrderList(String phoneId) {
		// TODO Auto-generated method stub
		return orderMapper.queryHistoryOrderList(phoneId);
	}

	public boolean publishOrder(RecordBean recordBean) {
		// TODO Auto-generated method stub
		return orderMapper.insertOrder(recordBean) == 1 ? true : false;
	}

	public boolean delOrder(String orderId) {
		// TODO Auto-generated method stub
		int result = orderMapper.delOrder(orderId);
		return result == 1 ? true : false;
	}

	public boolean updateOrderStatus(String orderId, int orderStatus) {
		// TODO Auto-generated method stub
		HashMap<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("orderId", orderId);
		hashMap.put("orderStatus", orderStatus);
		int result = orderMapper.updateOrderStatus(hashMap);
		return result == 1 ? true : false;
	}

	public RecordBean queryOrderDetail(String orderId) {
		// TODO Auto-generated method stub
		RecordBean recordBean = orderMapper.queryOrderDetail(orderId);
		if (recordBean != null) {
			List<AudioBean> audioBeans = audioMapper.queryAudioList("%" + recordBean.getOrderid() + "%");
			recordBean.setAudiolist(audioBeans);
		}
		return recordBean;
	}

	public List<RecordBean> queryUnderOrderList(String brokerId) {
		// TODO Auto-generated method stub
		return orderMapper.queryUnderOrderList(brokerId);
	}

	public boolean addAudioInfo(AudioBean audioBean) {
		// TODO Auto-generated method stub
		return audioMapper.insertAudio(audioBean) == 1 ? true : false;
	}

	public List<AudioBean> queryAudioList(String orderId) {
		// TODO Auto-generated method stub
		List<AudioBean> audioBeans = audioMapper.queryAudioList("%" + orderId + "%");
		if (audioBeans == null) {
			audioBeans = new ArrayList<AudioBean>();
		}
		return audioBeans;
	}

}
